import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from './utils/axios'
import api from 'utils/api'
import lodash from 'lodash'
import code from 'data/code'
import mes from 'data/mes'
import timeFormater from 'time-formater'

import 'element-ui/lib/theme-chalk/index.css'
import './plugins/element.js'

import { key2Value, id2Name } from 'utils/key2Value'

Vue.config.productionTip = false
Vue.prototype.axios = axios
Vue.prototype.lodash = lodash
Vue.prototype.ok = code.ok
Vue.prototype.mes = mes
Vue.prototype.api = api
Vue.prototype.timeFormater = timeFormater
Vue.prototype.key2Value = key2Value
Vue.prototype.id2Name = id2Name

router.beforeEach((to, from, next) => {
  const token = (localStorage.getItem('token') || store.state.token)
  if (!token && to.path !== '/login') router.replace({ path: '/login' })
  next()
})

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
